package com.forezp.datastruct;

/**
 * Created by forezp on 2017/12/5.
 */
public class ArrayStack<T> {

    private T[] items;
    private int capcity;
    private int size;
    private int top;


    public ArrayStack(int capcity) {
        this.capcity = capcity;
        items = (T[]) new Object[capcity];
    }

    public boolean isEmpty() {
        return size == 0;
    }

    public boolean isFull() {
        return size == capcity;
    }

    public boolean push(T data) {
        if (isFull()) {
            return false;
        }
        items[top++] = data;
        size++;
        return true;
    }

    public T pop() {
        if (isEmpty()) {
            return null;
        }
        size--;
        return items[--top];
    }

    public void iterate(){

        for (int i=0;i<top;i++){
            System.out.print(items[i]);
        }

    }
}
